<?php
/**
 * Created by PhpStorm.
 * User: bililovy
 * Date: 19-7-30
 * Time: 下午6:36
 * Description:
 */

namespace ServiceSdk\Services;


use xiaoyaoSDK\Libs\Remote;
use xiaoyaoSDK\Tools\Encrypt\RC4;

class BossSystemService extends BaseService
{
    private static $instance = null;

    /**
     * Description: 单例实例化
     * @return BossSystemService
     * @Author: Bililovy
     * @Date  : 19-6-10 下午9:56
     */
    public static function getInstance()
    {
        if (is_null(self::$instance) || self::$instance instanceof self) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * Description: 根据指定条件 和token获取网吧信息
     *
     * @param string $token
     * @param array $conditions 网吧id主键
     * @param array $field      要筛选的字段，默认空，则返回全部字段
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 19-8-25 下午3:52
     */
    public function getBarsInfo(string $token, array $conditions, $field = []): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode(['condition' => $conditions, 'field' => $field])));
        $response = Remote::post('boss_admin_url.get_bars', json_encode(['_secret_data' => $encryptData]), [], [
            'token:' . $token,
            'Content-Type:application/json;charset=UTF-8'
        ]);

        return $this->dealResponse($response);
    }

    /**
     * Description: 根据指定条件 和token获取网吧信息
     *
     * @param array $conditions 格式如下：
     *
     *                           {
     *                              "mobile":"",
     *                              "username":"",
     *                              "bar_name":"网络", // 此项是模糊匹配
     *                              "manager_num":""
     *                              }
     * @param array $field      要筛选的字段，默认空，则返回全部字段
     * @param int $page         当前页码
     * @param int $pageSize     每页数据量
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 19-8-25 下午3:52
     */
    public function getBarsList(array $conditions, array $field = [], int $page = 1, int $pageSize = 20): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode(['condition' => $conditions, 'field' => $field, 'page' => $page, 'page_size' => $pageSize])));
        $response = Remote::post('boss_admin_url.get_bar_list', json_encode(['_secret_data' => $encryptData]), [], [
            'Content-Type:application/json;charset=UTF-8'
        ]);

        return $this->dealResponse($response);
    }


    /**
     * Description: 根据网吧id 获取网吧是否实时在线
     *
     * @param string $token
     * @param array $barIds 指定网吧id，是主键id，非数字id，如： 1asgvgem56hv
     *
     * @return array
     * @Author: Bililovy
     * @throws \Exception
     * @Date  : 19-8-25 下午5:09
     */
    public function getBarsOnlineStatus(string $token, array $barIds): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode(['bar_id' => $barIds])));
        $response = Remote::post('boss_admin_url.get_bar_status', json_encode(['_secret_data' => $encryptData]), [], [
            'token:' . $token,
            'Content-Type:application/json;charset=UTF-8'
        ]);

        return $this->dealResponse($response);
    }

    /**
     * Description: 根据网吧id 获取网吧是否实时在线，与上述方法区别为，此方法不需要传入token，采用内部白名单ip验证规则
     *              无需再用token验证了
     *
     * @param array $barIds 指定网吧id，是主键id，非数字id，如： [1asgvgem56hv]
     *
     * @return array
     * @Author: Bililovy
     * @throws \Exception
     * @Date  : 19-8-25 下午5:09
     */
    public function checkBarsOnlineStatus(array $barIds): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode(['bar_id' => $barIds])));
        $response = Remote::post('boss_admin_url.get_online_status', json_encode(['_secret_data' => $encryptData]), [], [
            'Content-Type:application/json;charset=UTF-8'
        ]);

        return $this->dealResponse($response);
    }

    /**
     * Description: 根据网吧id 获取网吧是否实时在线
     *
     * @param string $token
     * @param array $barIds 指定网吧id，是主键id，非数字id，如： 1asgvgem56hv
     * @param string $date  指定要获取的日期，格式为：Y-m-d, 默认空，则获取当前时间前一天的数据
     * @param array $field  指定筛选的字段，默认空，即全部字段
     *
     * @return array
     * @Author: Bililovy
     * @throws \Exception
     * @Date  : 19-8-25 下午5:09
     */
    public function getBarsOnlineClient(string $token, array $barIds, string $date = '', array $field = []): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode(['bar_id' => $barIds, 'date' => $date, 'field' => $field])));
        $response = Remote::post('boss_admin_url.get_bar_online_client', json_encode(['_secret_data' => $encryptData]), [], [
            'token:' . $token,
            'Content-Type:application/json;charset=UTF-8'
        ]);

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取操作token ，一般是临时token
     *
     * @param string $code 请求code
     *
     * @return string
     * @Author: Bililovy
     * @throws \Exception
     * @Date  : 19-8-25 上午11:47
     */
    public function getOperationToken(string $code): string
    {
        $response = Remote::get('boss_admin_url.get_token', [], ['code' => base64_encode($code), 'decrypt_data' => 1]);
        $result = $this->dealResponse($response);
        $token = $result[ 'token' ] ?? '';

        return $token;
    }

    /**
     * Description: 注册一个新网吧
     *
     * @param array $params 网吧注册的信息，数据结构如下
     *
     *                      [
     *                          'user_name'=>'bililovy_fuck010',
     *                          'user_password'=>md5('1234555'),     // 这个密码必须将明文先 md5 加密在传入
     *                          'bar_boss_name'=>'盛趣时代',
     *                          'bar_name'=>'知道创于网咖',
     *                          'bar_cyber_number'=>'11',
     *                          'bar_region'=>'500116',
     *                          'bar_address'=>'武侯东三段府城大道',
     *                          'bar_boss_qq'=>'510100',
     *                          'bar_boss_mobile'=>'13211111111',
     *                          'phone_captcha':232322,
     *                          'bar_operation_type':0,     // optional
     *                          'bar_status':1,             // optional
     *                          'bar_channel'=>'指定渠道',  // optional
     *                          'sort_order'=>'12'          // optional
     *                      ]
     *  以上字段，如果 备注了 optional 的字段表示可选字段，如果没有传值，则会有默认值
     *
     * @return array
     * @Author: Bililovy
     * @throws \Exception
     * @Date  : 19-6-10 下午9:52
     */
    public function registerBar(array $params): array
    {
        $response = Remote::post('boss_admin_url.bar_register', json_encode($params));

        return $this->dealResponse($response);
    }

    /**
     * Description: 网吧老板或员工登录接口
     *
     * @param array $params 格式为：
     *                      {
     *                      "name": "xiaoyao_siyang001",
     *                      "pass_word": "e10adc3949ba59abbe56e057f20f883e",
     *                      "type": "1",
     *                      "decrypt_data":1
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-4-22 下午6:22
     */
    public function login(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.login', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 绑定通信服务接口
     *
     * @param array $params 格式如下：
     *                      {
     *                      "siteid": "fdsfdsf",
     *                      "error_code": "0",
     *                      "send_time": "187287554",
     *                      "command": 80003,
     *                      "token": "fdfdfdsfdsfdfdsfsdf",
     *                      "args": {
     *                      "client_id": 13323323443443,
     *                      "multi_bind": 0
     *                      }
     *                      };
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-4-22 下午6:21
     */
    public function bindActiveCommunication(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.bind_active_communication', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 更新网吧信息
     *
     * @param string $token 一次性token，请先用本文件中 getOperationToken() 方法生成token，然后
     *                      将生成的token值带入此方法
     * @param array $params
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 19-8-25 下午2:24
     */
    public function updateBarInfo(string $token, array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.bar_update', json_encode(['_secret_data' => $encryptData]), [], [
            'token:' . $token,
            'Content-Type:application/json;charset=UTF-8'
        ]);

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取客户端行为统计信息
     *
     * @param array $params 支持参数如下：
     *
     *                         {
     *                          "begin_time": "", // 开始时间，不传，则默认从当前计算钱7天的0点0分0秒
     *                          "end_time": "",   // 结束时间，不传，则默认当前时间
     *                          "page":1        // 当前页码，不传则默认第一页，该分页主要针对按网吧统计的时候
     *                                          // 对要显示的网吧进行分页
     *                                          // 因为网吧有几千上万家，因此需要每页100个网吧显示
     *                        }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-5-14 下午2:57
     */

    public function getClientStatistics(array $params = []): array
    {
        // 将数据加密传输
        if ( ! empty($params)) {
            $securityConfig = load_config_file('security');
            $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
            $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        }
        $response = Remote::post('boss_admin_url.get_yx_client_behavior_statistics', ! empty($params) ? json_encode(['_secret_data' => $encryptData]) : [], []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取小妖客户端终端总计
     *
     * @param array $params
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-8-24 下午5:03
     */
    public function getXyClientStatistics(array $params = []): array
    {
        // 将数据加密传输
        if ( ! empty($params)) {
            $securityConfig = load_config_file('security');
            $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
            $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        }
        $response = Remote::post('boss_admin_url.get_xy_client_statistics', ! empty($params) ? json_encode(['_secret_data' => $encryptData]) : [], []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 为网吧开启或关闭相应的应用业务
     *
     * @param array $params 格式为：
     *
     *                      {
     *                          "app_list": ["2ucmedhbz88j"], // 总后台的业务应用id
     *                          "bar_list":["all_bar"],     // 网吧主键id列表，如果包含了'all_bar'，则直接视为对所有网吧生效
     *                          "app_type":1000,            // 指定业务应用的类型，目前0-官方桌面应用，1000代表广告业务应用，其他的可根据实际情况指定
     *                          "type":"open",              // 对业务应用的操作类型 open 打开（启用）应用， close 关闭应用
     *                          "log_operation_info":{      // 此项选填， 如果带了此参数，则视为要写入操作日志，不传则不写日志
     *                              "operator_id":"1",      // 操作者id
     *                              "operator":"admin",     // 操作者名称
     *                              "platform":"admin",     // 操作平台，如admin后台，代理后台，网吧后台等
     *                              "description":"选择11家网吧批量开启了应用"  // 操作的描述，自定义
     *                          }
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-6-13 下午2:16
     */
    public function openOrCloseApp(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.app_open_close', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 保存（同步）总后台的业务信息到网吧管理后台的应用库
     *
     * @param array $params 结构如下：
     *
     *                   {
     *                      "app_list": [
     *                          {
     *                              "app_id": "2u3dz02juz7i",
     *                              "app_name": "大神楼比",
     *                              "app_path": "c:\\prog\\dfd.exe1",
     *                              "sort_order": 12,
     *                              "app_type": 1000,
     *                              "enable":1,
     *                              "app_icon": []
     *                          },
     *                          ....
     *                      ]
     *                  }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-6-13 下午2:21
     */
    public function saveAppToBarAppLibrary(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.save_to_bar_app_library', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取网吧正在使用的应用列表
     *
     * @param array $params 格式如下：
     *
     *                      {
     *                          "app_id"=>["appid",...], // 应用id
     *                          "bar_id": ["2ph9j5i09eol","2g4z1x3iqrzc"],
     *                          "app_type": 1000    // 应用类型
     *                          "field"=>["app_name"] // 要检索的字段
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-6-13 下午2:23
     */
    public function getBarAppList(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.get_bar_app_list', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取应用列表
     *
     * @param array $params 格式如下：
     *
     *                      {
     *                          "app_id"=>["appid",...], // 应用id
     *                          "app_type": 100    // 应用类型
     *                          "field"=>["app_name"] // 要检索的字段
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-6-13 下午2:23
     */
    public function getAppLibrary(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.get_app_library_list', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 删除应用库的应用
     *
     * @param array $params 格式如下：
     *
     *                      {
     *                      "app_list": [
     *                          "2ucmedhbz88j"
     *                      ],
     *                      "app_type": 1000     // 应用类型
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-6-13 下午2:24  `
     */
    public function removeAppFromBarAppLibrary(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.remove_bar_app_library', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取网吧在线信息统计
     *
     * @param array $params
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-7-23 下午2:55
     */
    public function getOnlineStatisticsInfo(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.get_online_statistics', json_encode(['_secret_data' => $encryptData]));

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取网吧在线信息统计
     *
     * @param array $params
     *
     *              {
     *                  "page":1,
     *                  "type":1
     *              }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-7-23 下午2:55
     */
    public function getOnlineLossList(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.get_online_loss', json_encode(['_secret_data' => $encryptData]));

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取保险保单列表
     *
     * @param array $params 格式如下：
     *
     *                      {
     *                          "page":"1",
     *                          "page_size":"20",
     *                          "keyword":"",   // 对联系人、网吧名称、手机号进行检索
     *                          "begin_time":"2020-08-25",
     *                          "end_time":"2020-09-01",
     *                          "insurance_type":0,  // 保险类型，默认所有类型
     *                          "status":-1         // 当前状态，默认所有状态
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-9-1 上午10:23
     */
    public function getInsuranceList(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.get_insurance_list', json_encode(['_secret_data' => $encryptData]));

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取保险保单列表
     *
     * @param array $params 格式如下：
     *                      {
     *                      "insurance_id":"2yiq82gmfqag",
     *                      "bar_name":"我按的21",
     *                      "contact_name":"12333443322",
     *                      "contact_phone":"13233444444",
     *                      "bar_address":"地方的开发大疯掉了房间",
     *                      "bar_scale":"12平方",
     *                      "insurance_type":"2",
     *                      "remark":"冯绍峰的是",
     *                      "operator":"superadmin"
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-9-1 上午10:23
     */
    public function updateInsuranceData(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.update_insurance', json_encode(['_secret_data' => $encryptData]));

        return $this->dealResponse($response);
    }

    /**
     * Description: 获取保险保单列表
     *
     * @param array $params 格式如下：
     *
     *                      {
     *                          "page":"1",
     *                          "page_size":"20",
     *                          "insurance_id":"fdsfdsf",  // 保险数据主键id
     *                      }
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-9-1 上午10:23
     */
    public function getInsuranceOperateLog(array $params): array
    {
        // 将数据加密传输
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.get_insurance_operate_log', json_encode(['_secret_data' => $encryptData]));

        return $this->dealResponse($response);
    }

    /**
     * Description: 其他系统数据改动，推送到下端
     *
     * @param array $barIds    要推送到的网吧，不能写空，如果要推送到所有网吧，则传入 ['all']
     * @param array $primaries 格式必须为：
     *
     *                         [
     *                          352=>['iud1','id2',...] 其中，键为 同步表id，去yx_newboss项目查询
     *                         ]
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-9-24 下午3:44
     */
    public function sendDbSaveToClient(array $barIds, array $primaries, string $pkName = 'id'): array
    {
        // 将数据加密传输
        $params = [
            'type' => 'db',
            'sync_type' => 'save',
            'pk_name' => $pkName,
            'send_to' => $barIds,
            'data' => $primaries
        ];
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.sync_data', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }

    /**
     * Description: 其他系统数据删除，推送到下端
     *
     * @param array $barIds    要推送到的网吧，不能写空，如果要推送到所有网吧，则传入 ['all']
     * @param array $primaries 格式必须为：
     *
     *                         [
     *                          352=>['iud1','id2',...] 其中，键为 同步表id，去yx_newboss项目查询
     *                         ]
     *
     * @return array
     * @throws \Exception
     * @Author: Bililovy
     * @Date  : 20-9-24 下午3:44
     */
    public function sendDbDeleteToClient(array $barIds, array $primaries, string $pkName = 'id'): array
    {
        // 将数据加密传输
        $params = [
            'type' => 'db',
            'sync_type' => 'delete',
            'pk_name' => $pkName,
            'send_to' => $barIds,
            'data' => $primaries
        ];
        $securityConfig = load_config_file('security');
        $privateKey = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
        $encryptData = base64_encode(RC4::crypt($privateKey, json_encode($params)));
        $response = Remote::post('boss_admin_url.sync_data', json_encode(['_secret_data' => $encryptData]), []);

        return $this->dealResponse($response);
    }
    
    /**
     * Description: 统一处理改服务下的返回值
     *
     * @param array $response
     *
     * @return array
     * @Author: Bililovy
     * @Date  : 19-6-10 下午9:48
     */
    protected function dealResponse($response): array
    {
        if ( ! empty($response[ '_secret_data' ])) {
            $securityConfig = load_config_file('security');
            $rc4Key = $securityConfig[ 'rc4_encrypt_key' ] ?? '';
            // 表示是加密数据，则县解密
            $response = json_decode(RC4::crypt($rc4Key, base64_decode($response[ '_secret_data' ])), true);
        }
        $this->setErrorCode($response[ 'error_code' ] ?? 0);
        if (isset($response[ 'error_code' ]) && $response[ 'error_code' ] === self::SUCCESS_CODE) {
            $response = empty($response[ 'data' ]) ? (empty($response[ 'args' ]) ? ['success'] : $response[ 'args' ]) : $response[ 'data' ];
        } else {
            if (isset($response[ 'message' ])) {
                if (is_array($response[ 'message' ])) {
                    $this->setErrorMessage(json_encode($response[ 'message' ], 320));
                } else {
                    $this->setErrorMessage($response[ 'message' ]);
                }
            } else if (is_string($response)) {
                $this->setErrorMessage($response);
            } else {
                $this->setErrorMessage('请求处理失败，请检查原因');
            }
            $response = [];
        }

        return $response;
    }
}